package com.ydc.ln.tutorial.mail.oracle;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

import javax.activation.DataContentHandler;
import javax.activation.DataSource;

public class text_plain implements DataContentHandler{

	// creates a string from a "text/plain" data source
	public Object getContent(DataSource dataSource) throws IOException {
		InputStream inputStream = dataSource.getInputStream();
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		int c;
		while((c = inputStream.read()) != -1) {
			outputStream.write(c);
		}
		String charset = "";//getCharSet(dataSource.getContentType());
		return new String(outputStream.toByteArray(), charset);
	}

	public Object getTransferData(DataFlavor arg0, DataSource arg1)
			throws UnsupportedFlavorException, IOException {
		return null;
	}

	public DataFlavor[] getTransferDataFlavors() {
		return null;
	}

	// creates a byte stream from a string
	public void writeTo(Object object, String type, OutputStream outputStream)
			throws IOException {
		OutputStreamWriter writer = null;//new OutputStreamWriter(outputStream, getCharset(type));
		String string = (String)object;
		writer.write(string, 0, string.length());
		writer.flush();
	}

}
